package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootScinfo;
import org.footballmanager.pandafootball.system.domain.enums.JNFL;
import org.footballmanager.pandafootball.system.form.impl.FootScinfoSearchForm;
import org.footballmanager.pandafootball.system.service.FootPersonService;
import org.footballmanager.pandafootball.system.service.FootScinfoService;
import org.footballmanager.pandafootball.system.service.FootTableTitleService;
import org.footballmanager.pandafootball.system.service.FootUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@SessionAttributes("footScinfoSearchForm")
@RequestMapping("/foot/footScinfo")
public class FootScinfoController extends BaseController{
	/* 实体名称 */
	private static final String ENTITYNAME = "footScinfo";
	private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
	private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.FOOT, ENTITYNAME);

	@Autowired
	private FootScinfoService footScinfoService;
	@Autowired
	private FootPersonService footPersonService;
	@Autowired
	private FootUserService footUserService;
    @Autowired
    private FootTableTitleService footTableTitleService;

	/**
	 * 初始化
	 * @param map 参数
	 * @param footScinfoSearchForm 条件参数
	 */
	@ModelAttribute
	public void init(Model map, @ModelAttribute FootScinfoSearchForm footScinfoSearchForm){
		map.addAttribute("qyList", footPersonService.getall());
		map.addAttribute("userList", footUserService.getall());
        map.addAttribute("head", footTableTitleService.findByTableName(Constants.PERSONTABLE));
		FootScinfoSearchForm newFootScinfoSearchForm = new FootScinfoSearchForm();
		if(footScinfoSearchForm != null){
			newFootScinfoSearchForm = footScinfoSearchForm;
		}
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootScinfoSearchForm);
	}

	@RequestMapping(value="/search")
	public String search(Model map, @ModelAttribute FootScinfoSearchForm footScinfoSearchForm) {
        footScinfoService.search(ENTITYNAME, map, footScinfoSearchForm);
		return LISTPAGE;
	}
	
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String openViewPage(Model map, @RequestParam Long id, @ModelAttribute FootScinfoSearchForm footScinfoSearchForm) {
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footScinfoSearchForm);
        map.addAttribute("basicSkills", footTableTitleService.findByTableNameAndJnfl(Constants.PERSONTABLE, JNFL.BASIC));
        map.addAttribute("linkageSkills", footTableTitleService.findByTableNameAndJnfl(Constants.PERSONTABLE, JNFL.LINKAGE));
        FootScinfo sc = footScinfoService.get(id);
		map.addAttribute("footPerson", footPersonService.get(sc.getQyId()));
		return VIEWPAGE;
	}	
		
}
